package javagprssrv.DataBase;


import javagprssrv.JGS_Param;
import org.apache.log4j.Logger;

public class TrdDBSQLRun extends java.lang.Thread
{
    java.lang.String SQLString;
    Logger logger = Logger.getLogger(TrdDBSQLRun.class);
    public TrdDBSQLRun() {
        super("TrdDBSQLRun");
        this.SQLString = "";
    }
    
    @java.lang.Override
    public void run() {
    	  try
    	    {
    	      while (true)
    	      {
    	        Thread.sleep(20L);
    	        synchronized (JGS_Param.UnSavedDBSQLString)
    	        {
    	          this.SQLString = "";
    	          if (JGS_Param.UnSavedDBSQLString.size() > 0) {
    	            this.SQLString = ((String)JGS_Param.UnSavedDBSQLString.remove(0)).trim();
    	          }
    	          if (JGS_Param.UnSavedDBSQLString.size() > 10000) {
    	            JGS_Param.UnSavedDBSQLString.clear();
                    logger.warn("UnSavedDBSQLString 超上限，队列中数据被清除");
    	          }
    	        }
    	        if (this.SQLString.length() != 0)
    	        {
    	          DBSQLExecute dbse = new DBSQLExecute();
    	          int idx_db = 0;
    	          try
    	          {
    	            if (this.SQLString.toUpperCase().contains("T_MINUTE"))
    	            {
    	              idx_db = 1;
    	              dbse.SQL_Update(idx_db, this.SQLString);
    	            }
//    	            else
//    	            {
//    	              idx_db = 0;
//    	              dbse.SQL_Update(idx_db, this.SQLString);
//    	            }
    	            else if (this.SQLString.toUpperCase().contains("R_HGS"))
    	            {
    	              idx_db = 1;
    	              dbse.SQL_Update(idx_db, this.SQLString);
    	            }
    	            else
    	            {
    	              idx_db = 0;
    	              dbse.SQL_Update(idx_db, this.SQLString);
    	            }
//    	            dbse.SQL_Update(idx_db, this.SQLString);
    	            JGS_Param.countSavedSQL_Success += 1;
    	            JGS_Param.myLog.ShowLog("[SQL执行Success(" + idx_db + ")] " + this.SQLString, Boolean.TRUE, Boolean.TRUE);
    	          }
    	          catch (Exception e)
    	          {
    	            JGS_Param.countSavedSQL_Failure += 1;
    	            JGS_Param.myLog.ShowLog("[SQL执行Success(" + idx_db + ")] " + this.SQLString, Boolean.TRUE, Boolean.TRUE);
    	          }
    	          dbse = null;
    	        }
    	      }
    	    }
    	    catch (Exception localException1) {}
    }
}
